﻿@{
    const string cardId = "order-average-report-card";
    const string hideCardAttributeName = "Reports.HideOrderAverageReportCard";
    var hideCard = await genericAttributeService.GetAttributeAsync<bool>(await workContext.GetCurrentCustomerAsync(), hideCardAttributeName);
}

<div class="card card-primary card-outline @if(hideCard){<text>collapsed-card</text>}" id="@cardId">
    <div class="card-header with-border">
        <h3 class="card-title">
            <i class="fas fa-money-check-dollar"></i>
            @T("Admin.SalesReport.Average")
        </h3>
        <div class="card-tools float-right">
            <button class="btn btn-tool" data-card-widget="collapse">
                @if (hideCard)
                {
                    <text><i class="fas fa-plus"></i></text>
                }
                else
                {
                    <text><i class="fas fa-minus"></i></text>
                }
            </button>
        </div>
    </div>
    <script>
        $(function() {
            var collapsed = !$('#@cardId').hasClass('collapsed-card');
            if (collapsed) {
                $('#orderAverageReport').load('@Url.Action("GetOrderAverage", "Home")');
            }

            $('#@cardId').on('click', 'button[data-card-widget="collapse"]', function () {
                collapsed = !$('#@cardId').hasClass('collapsed-card');
                saveUserPreferences('@(Url.Action("SavePreference", "Preferences"))', '@hideCardAttributeName', collapsed);
                if (!collapsed) {
                    $('#orderAverageReport').load('@Url.Action("GetOrderAverage", "Home")');
                }
            });
        });
    </script>
    <div class="card-body" style="padding-bottom: 22px;">
        <div id="orderAverageReport"></div>
    </div>
</div>